package com.example.demo.Repository;

import com.example.demo.Entity.CurrentStorage;
import com.example.demo.Entity.Item;
import com.example.demo.Entity.Shelf;
import com.example.demo.Entity.Warehouse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Repository
public interface CurrentStorageRepo extends JpaRepository<CurrentStorage, Long> {
    // 使用JPQL查询仓库中所有物品的当前数量
    @Query("SELECT cs FROM CurrentStorage cs WHERE cs.warehouse = :warehouse")
    List<CurrentStorage> findByWarehouse(@Param("warehouse") Warehouse warehouse);

    // 使用JPQL查询仓库中所有物品的当前数量
    //@Query("SELECT cs FROM CurrentStorage cs WHERE cs.warehouse = :warehouse")
    List<CurrentStorage> findByItem(Item item);

    // 根据仓库和物品查询当前存储量
    @Query("SELECT cs FROM CurrentStorage cs WHERE cs.warehouse.id = :warehouseId AND cs.item.id = :itemId")
    Optional<CurrentStorage> findByWarehouseIdAndItemId(@Param("warehouseId") Long warehouseId, @Param("itemId") Long itemId);



}
